;--------------------------------------------------------
; File Created by SDCC : free open source ANSI-C Compiler
; Version 2.8.0 #5117 (Mar 23 2008) (MINGW32)
; This file was generated Tue Jun 03 22:17:51 2008
;--------------------------------------------------------
	.module pwm
	.optsdcc -mmcs51 --model-small
	
;--------------------------------------------------------
; Public variables in this module
;--------------------------------------------------------
	.globl _main
	.globl _timer0_isr
	.globl _serial_isr
	.globl _CY
	.globl _AC
	.globl _F0
	.globl _RS1
	.globl _RS0
	.globl _OV
	.globl _F1
	.globl _P
	.globl _PS
	.globl _PT1
	.globl _PX1
	.globl _PT0
	.globl _PX0
	.globl _RD
	.globl _WR
	.globl _T1
	.globl _T0
	.globl _INT1
	.globl _INT0
	.globl _TXD
	.globl _RXD
	.globl _P3_7
	.globl _P3_6
	.globl _P3_5
	.globl _P3_4
	.globl _P3_3
	.globl _P3_2
	.globl _P3_1
	.globl _P3_0
	.globl _EA
	.globl _ES
	.globl _ET1
	.globl _EX1
	.globl _ET0
	.globl _EX0
	.globl _P2_7
	.globl _P2_6
	.globl _P2_5
	.globl _P2_4
	.globl _P2_3
	.globl _P2_2
	.globl _P2_1
	.globl _P2_0
	.globl _SM0
	.globl _SM1
	.globl _SM2
	.globl _REN
	.globl _TB8
	.globl _RB8
	.globl _TI
	.globl _RI
	.globl _P1_7
	.globl _P1_6
	.globl _P1_5
	.globl _P1_4
	.globl _P1_3
	.globl _P1_2
	.globl _P1_1
	.globl _P1_0
	.globl _TF1
	.globl _TR1
	.globl _TF0
	.globl _TR0
	.globl _IE1
	.globl _IT1
	.globl _IE0
	.globl _IT0
	.globl _P0_7
	.globl _P0_6
	.globl _P0_5
	.globl _P0_4
	.globl _P0_3
	.globl _P0_2
	.globl _P0_1
	.globl _P0_0
	.globl _B
	.globl _ACC
	.globl _PSW
	.globl _IP
	.globl _P3
	.globl _IE
	.globl _P2
	.globl _SBUF
	.globl _SCON
	.globl _P1
	.globl _TH1
	.globl _TH0
	.globl _TL1
	.globl _TL0
	.globl _TMOD
	.globl _TCON
	.globl _PCON
	.globl _DPH
	.globl _DPL
	.globl _SP
	.globl _P0
	.globl _i2c_write_PARM_2
	.globl _SCALE_FACTOR
	.globl _ch1duty
	.globl _ch0duty
	.globl _timer0_of
	.globl _beat_send
	.globl _uart_data
	.globl _frame_complete
	.globl _frame_started
	.globl _index
	.globl _packet
	.globl _InitSerial
	.globl _Tx
	.globl _Rx
	.globl _update
	.globl _i2c_read
	.globl _i2c_write
	.globl _i2c_start
	.globl _i2c_stop
	.globl _i2c_tx
	.globl _i2c_rx
;--------------------------------------------------------
; special function registers
;--------------------------------------------------------
	.area RSEG    (DATA)
_P0	=	0x0080
_SP	=	0x0081
_DPL	=	0x0082
_DPH	=	0x0083
_PCON	=	0x0087
_TCON	=	0x0088
_TMOD	=	0x0089
_TL0	=	0x008a
_TL1	=	0x008b
_TH0	=	0x008c
_TH1	=	0x008d
_P1	=	0x0090
_SCON	=	0x0098
_SBUF	=	0x0099
_P2	=	0x00a0
_IE	=	0x00a8
_P3	=	0x00b0
_IP	=	0x00b8
_PSW	=	0x00d0
_ACC	=	0x00e0
_B	=	0x00f0
;--------------------------------------------------------
; special function bits
;--------------------------------------------------------
	.area RSEG    (DATA)
_P0_0	=	0x0080
_P0_1	=	0x0081
_P0_2	=	0x0082
_P0_3	=	0x0083
_P0_4	=	0x0084
_P0_5	=	0x0085
_P0_6	=	0x0086
_P0_7	=	0x0087
_IT0	=	0x0088
_IE0	=	0x0089
_IT1	=	0x008a
_IE1	=	0x008b
_TR0	=	0x008c
_TF0	=	0x008d
_TR1	=	0x008e
_TF1	=	0x008f
_P1_0	=	0x0090
_P1_1	=	0x0091
_P1_2	=	0x0092
_P1_3	=	0x0093
_P1_4	=	0x0094
_P1_5	=	0x0095
_P1_6	=	0x0096
_P1_7	=	0x0097
_RI	=	0x0098
_TI	=	0x0099
_RB8	=	0x009a
_TB8	=	0x009b
_REN	=	0x009c
_SM2	=	0x009d
_SM1	=	0x009e
_SM0	=	0x009f
_P2_0	=	0x00a0
_P2_1	=	0x00a1
_P2_2	=	0x00a2
_P2_3	=	0x00a3
_P2_4	=	0x00a4
_P2_5	=	0x00a5
_P2_6	=	0x00a6
_P2_7	=	0x00a7
_EX0	=	0x00a8
_ET0	=	0x00a9
_EX1	=	0x00aa
_ET1	=	0x00ab
_ES	=	0x00ac
_EA	=	0x00af
_P3_0	=	0x00b0
_P3_1	=	0x00b1
_P3_2	=	0x00b2
_P3_3	=	0x00b3
_P3_4	=	0x00b4
_P3_5	=	0x00b5
_P3_6	=	0x00b6
_P3_7	=	0x00b7
_RXD	=	0x00b0
_TXD	=	0x00b1
_INT0	=	0x00b2
_INT1	=	0x00b3
_T0	=	0x00b4
_T1	=	0x00b5
_WR	=	0x00b6
_RD	=	0x00b7
_PX0	=	0x00b8
_PT0	=	0x00b9
_PX1	=	0x00ba
_PT1	=	0x00bb
_PS	=	0x00bc
_P	=	0x00d0
_F1	=	0x00d1
_OV	=	0x00d2
_RS0	=	0x00d3
_RS1	=	0x00d4
_F0	=	0x00d5
_AC	=	0x00d6
_CY	=	0x00d7
;--------------------------------------------------------
; overlayable register banks
;--------------------------------------------------------
	.area REG_BANK_0	(REL,OVR,DATA)
	.ds 8
;--------------------------------------------------------
; internal ram data
;--------------------------------------------------------
	.area DSEG    (DATA)
_packet::
	.ds 7
_index::
	.ds 1
_frame_started::
	.ds 1
_frame_complete::
	.ds 1
_uart_data::
	.ds 1
_beat_send::
	.ds 1
_timer0_of::
	.ds 1
_ch0duty::
	.ds 1
_ch1duty::
	.ds 1
_SCALE_FACTOR::
	.ds 1
_i2c_write_PARM_2:
	.ds 1
;--------------------------------------------------------
; overlayable items in internal ram 
;--------------------------------------------------------
	.area	OSEG    (OVR,DATA)
	.area	OSEG    (OVR,DATA)
	.area	OSEG    (OVR,DATA)
	.area	OSEG    (OVR,DATA)
;--------------------------------------------------------
; Stack segment in internal ram 
;--------------------------------------------------------
	.area	SSEG	(DATA)
__start__stack:
	.ds	1

;--------------------------------------------------------
; indirectly addressable internal ram data
;--------------------------------------------------------
	.area ISEG    (DATA)
;--------------------------------------------------------
; absolute internal ram data
;--------------------------------------------------------
	.area IABS    (ABS,DATA)
	.area IABS    (ABS,DATA)
;--------------------------------------------------------
; bit data
;--------------------------------------------------------
	.area BSEG    (BIT)
_i2c_tx_ackbit_1_1:
	.ds 1
;--------------------------------------------------------
; paged external ram data
;--------------------------------------------------------
	.area PSEG    (PAG,XDATA)
;--------------------------------------------------------
; external ram data
;--------------------------------------------------------
	.area XSEG    (XDATA)
;--------------------------------------------------------
; absolute external ram data
;--------------------------------------------------------
	.area XABS    (ABS,XDATA)
;--------------------------------------------------------
; external initialized ram data
;--------------------------------------------------------
	.area XISEG   (XDATA)
	.area HOME    (CODE)
	.area GSINIT0 (CODE)
	.area GSINIT1 (CODE)
	.area GSINIT2 (CODE)
	.area GSINIT3 (CODE)
	.area GSINIT4 (CODE)
	.area GSINIT5 (CODE)
	.area GSINIT  (CODE)
	.area GSFINAL (CODE)
	.area CSEG    (CODE)
;--------------------------------------------------------
; interrupt vector 
;--------------------------------------------------------
	.area HOME    (CODE)
__interrupt_vect:
	ljmp	__sdcc_gsinit_startup
	reti
	.ds	7
	ljmp	_timer0_isr
	.ds	5
	reti
	.ds	7
	reti
	.ds	7
	ljmp	_serial_isr
;--------------------------------------------------------
; global & static initialisations
;--------------------------------------------------------
	.area HOME    (CODE)
	.area GSINIT  (CODE)
	.area GSFINAL (CODE)
	.area GSINIT  (CODE)
	.globl __sdcc_gsinit_startup
	.globl __sdcc_program_startup
	.globl __start__stack
	.globl __mcs51_genXINIT
	.globl __mcs51_genXRAMCLEAR
	.globl __mcs51_genRAMCLEAR
	.area GSFINAL (CODE)
	ljmp	__sdcc_program_startup
;--------------------------------------------------------
; Home
;--------------------------------------------------------
	.area HOME    (CODE)
	.area HOME    (CODE)
__sdcc_program_startup:
	lcall	_main
;	return from main will lock up
	sjmp .
;--------------------------------------------------------
; code
;--------------------------------------------------------
	.area CSEG    (CODE)
;------------------------------------------------------------
;Allocation info for local variables in function 'InitSerial'
;------------------------------------------------------------
;------------------------------------------------------------
;	pwm.c:117: void InitSerial()
;	-----------------------------------------
;	 function InitSerial
;	-----------------------------------------
_InitSerial:
	ar2 = 0x02
	ar3 = 0x03
	ar4 = 0x04
	ar5 = 0x05
	ar6 = 0x06
	ar7 = 0x07
	ar0 = 0x00
	ar1 = 0x01
;	pwm.c:121: TR1 = 0; //disable timer before configuring mode
	clr	_TR1
;	pwm.c:122: TF1 = 0;//maybe necessary
	clr	_TF1
;	pwm.c:124: TI = 0;
	clr	_TI
;	pwm.c:125: RI = 0;
	clr	_RI
;	pwm.c:127: PCON = 0x80; //double this baudrate (SMOD = 1)
	mov	_PCON,#0x80
;	pwm.c:128: SCON = 0x50; //select mode, enable reception
	mov	_SCON,#0x50
;	pwm.c:131: TH1 = 255; //57600 bps @ 11.0592 (SMOD = 1)     
	mov	_TH1,#0xFF
;	pwm.c:135: TMOD = (TMOD & 0x0F) | 0x20; //set timer #1 for 8 bit auto-reload; lower nible timer0 config'd as 16-bit timer
	mov	a,#0x0F
	anl	a,_TMOD
	mov	b,a
	mov	a,#0x20
	orl	a,b
	mov	_TMOD,a
;	pwm.c:137: TR1 = 1; //bit 6 of TCON to enable timer 1;  
	setb	_TR1
;	pwm.c:138: return;
	ret
;------------------------------------------------------------
;Allocation info for local variables in function 'Tx'
;------------------------------------------------------------
;b                         Allocated to registers 
;------------------------------------------------------------
;	pwm.c:141: void Tx(char b)
;	-----------------------------------------
;	 function Tx
;	-----------------------------------------
_Tx:
;	pwm.c:143: TI = 0;
	clr	_TI
;	pwm.c:145: _asm mov _SBUF, dpl _endasm;
	 mov _SBUF, dpl 
;	pwm.c:146: while(!TI);
00101$:
	jnb	_TI,00101$
;	pwm.c:147: return;
	ret
;------------------------------------------------------------
;Allocation info for local variables in function 'Rx'
;------------------------------------------------------------
;------------------------------------------------------------
;	pwm.c:150: char Rx()
;	-----------------------------------------
;	 function Rx
;	-----------------------------------------
_Rx:
;	pwm.c:152: RI = 0;
	clr	_RI
;	pwm.c:153: while(!RI);
00101$:
	jnb	_RI,00101$
;	pwm.c:155: return SBUF;
	mov	dpl,_SBUF
	ret
;------------------------------------------------------------
;Allocation info for local variables in function 'serial_isr'
;------------------------------------------------------------
;------------------------------------------------------------
;	pwm.c:160: void serial_isr(void) interrupt 4
;	-----------------------------------------
;	 function serial_isr
;	-----------------------------------------
_serial_isr:
	push	acc
	push	ar0
	push	psw
	mov	psw,#0x00
;	pwm.c:238: TI = 0;//just incase to prevent repetitive interrupting
;	pwm.c:178: RI = 0; // clear reception flag for next reception 
	jbc	_RI,00129$
	ljmp	00119$
00129$:
;	pwm.c:179: uart_data = SBUF; 
	mov	_uart_data,_SBUF
;	pwm.c:184: if(!frame_complete)
	mov	a,_frame_complete
	jz	00130$
	ljmp	00119$
00130$:
;	pwm.c:186: if(frame_started) {
	mov	a,_frame_started
	jz	00114$
;	pwm.c:187: packet[index] = uart_data;              
	mov	a,_index
	add	a,#_packet
	mov	r0,a
	mov	@r0,_uart_data
;	pwm.c:189: if(index == 6)
	mov	a,#0x06
	cjne	a,_index,00102$
;	pwm.c:191: frame_complete = 1; //flag that a frame has completed and ready for processing by main() 
	mov	_frame_complete,#0x01
;	pwm.c:192: frame_started = 0; //reset for next transmission
	mov	_frame_started,#0x00
	sjmp	00119$
00102$:
;	pwm.c:195: index++;
	inc	_index
	sjmp	00119$
00114$:
;	pwm.c:197: } else if(uart_data == 'F') { //start character receceived for update frame
	mov	a,#0x46
	cjne	a,_uart_data,00111$
;	pwm.c:199: TR0 = 0;
	clr	_TR0
;	pwm.c:200: TH0 = 0;
	mov	_TH0,#0x00
;	pwm.c:201: TL0 = 0;
	mov	_TL0,#0x00
;	pwm.c:202: timer0_of = 0;
	mov	_timer0_of,#0x00
;	pwm.c:204: frame_started = 1;
	mov	_frame_started,#0x01
;	pwm.c:205: index = 1;
	mov	_index,#0x01
;	pwm.c:206: packet[0] = uart_data;
	mov	_packet,_uart_data
	sjmp	00119$
00111$:
;	pwm.c:208: } else if(uart_data == CMD_BEAT+1) { //received a beat response 
	mov	a,#0x47
	cjne	a,_uart_data,00108$
;	pwm.c:213: TR0 = 0;
	clr	_TR0
;	pwm.c:214: TH0 = 0;
	mov	_TH0,#0x00
;	pwm.c:215: TL0 = 0;
	mov	_TL0,#0x00
;	pwm.c:216: timer0_of = 0;
	mov	_timer0_of,#0x00
;	pwm.c:219: nOE = 0;
	clr	_P2_0
	sjmp	00119$
00108$:
;	pwm.c:220: } else if(uart_data == 'C') { 
	mov	a,#0x43
	cjne	a,_uart_data,00105$
;	pwm.c:222: TR0 = 0;
	clr	_TR0
;	pwm.c:223: TH0 = 0;
	mov	_TH0,#0x00
;	pwm.c:224: TL0 = 0;
	mov	_TL0,#0x00
;	pwm.c:225: timer0_of = 0;
	mov	_timer0_of,#0x00
;	pwm.c:227: frame_started = 1;
	mov	_frame_started,#0x01
;	pwm.c:228: index = 1;
	mov	_index,#0x01
;	pwm.c:229: packet[0] = uart_data;
	mov	_packet,_uart_data
	sjmp	00119$
00105$:
;	pwm.c:233: nOE = 1;        
	setb	_P2_0
00119$:
;	pwm.c:238: TI = 0;//just incase to prevent repetitive interrupting
	clr	_TI
;	pwm.c:243: return;
	pop	psw
	pop	ar0
	pop	acc
	reti
;	eliminated unneeded push/pop ar1
;	eliminated unneeded push/pop dpl
;	eliminated unneeded push/pop dph
;	eliminated unneeded push/pop b
;------------------------------------------------------------
;Allocation info for local variables in function 'timer0_isr'
;------------------------------------------------------------
;------------------------------------------------------------
;	pwm.c:246: void timer0_isr() interrupt 1 //_naked
;	-----------------------------------------
;	 function timer0_isr
;	-----------------------------------------
_timer0_isr:
	push	acc
	push	psw
	mov	psw,#0x00
;	pwm.c:248: timer0_of++;
	inc	_timer0_of
;	pwm.c:251: beat_send = 1;
	mov	_beat_send,#0x01
;	pwm.c:261: if(timer0_of == 90) { //uhoh watchdog biting
	mov	a,#0x5A
	cjne	a,_timer0_of,00103$
;	pwm.c:263: timer0_of = 0;
	mov	_timer0_of,#0x00
;	pwm.c:266: P2 = 0;
	mov	_P2,#0x00
;	pwm.c:267: P0 = 0;
	mov	_P0,#0x00
;	pwm.c:269: LED0 = !LED0;
	cpl	_P0_0
;	pwm.c:271: nOE = 1; //disable outputs
	setb	_P2_0
;	pwm.c:272: frame_started = 0;
	mov	_frame_started,#0x00
;	pwm.c:276: TI = 0;
	clr	_TI
;	pwm.c:277: SBUF = REQ_PACK_ISR;
	mov	_SBUF,#0x73
00103$:
	pop	psw
	pop	acc
	reti
;	eliminated unneeded push/pop dpl
;	eliminated unneeded push/pop dph
;	eliminated unneeded push/pop b
;------------------------------------------------------------
;Allocation info for local variables in function 'main'
;------------------------------------------------------------
;i                         Allocated to registers r2 r3 
;------------------------------------------------------------
;	pwm.c:288: void main(void)
;	-----------------------------------------
;	 function main
;	-----------------------------------------
_main:
;	pwm.c:296: ch0duty = 0;
	mov	_ch0duty,#0x00
;	pwm.c:297: ch1duty = 0;
	mov	_ch1duty,#0x00
;	pwm.c:299: P2 = 0;
	mov	_P2,#0x00
;	pwm.c:300: P0 = 0;
	mov	_P0,#0x00
;	pwm.c:301: SCALE_FACTOR = 5;
	mov	_SCALE_FACTOR,#0x05
;	pwm.c:303: index = 0;
	mov	_index,#0x00
;	pwm.c:304: frame_started = 0;
	mov	_frame_started,#0x00
;	pwm.c:305: frame_complete = 0;
	mov	_frame_complete,#0x00
;	pwm.c:306: nOE = 1;
	setb	_P2_0
;	pwm.c:308: timer0_of = 0;
	mov	_timer0_of,#0x00
;	pwm.c:309: beat_send = 0;
	mov	_beat_send,#0x00
;	pwm.c:311: InitSerial();
	lcall	_InitSerial
;	pwm.c:314: ES = 1; // Enable serial interrupt
	setb	_ES
;	pwm.c:315: ET0 = 1; //IE.1 timer0 interrupt
	setb	_ET0
;	pwm.c:316: EA = 1; // Enable global interrupt
	setb	_EA
;	pwm.c:318: PS = 1; //set serial interrupt as slightly higher priority, maybe needed since timer0 overflows quickly
	setb	_PS
;	pwm.c:321: TI = 0;
	clr	_TI
;	pwm.c:322: SBUF = INTERFACE_ACTIVE; //send interface active
	mov	_SBUF,#0xAF
;	pwm.c:324: while(1)
00120$:
;	pwm.c:334: if(beat_send)
	mov	a,_beat_send
	jz	00102$
;	pwm.c:336: beat_send = 0;
	mov	_beat_send,#0x00
;	pwm.c:338: SBUF = CMD_BEAT; 
	mov	_SBUF,#0x46
00102$:
;	pwm.c:341: TR0 = 1; //enable timer0 for 'pseudo-watchdog'
	setb	_TR0
;	pwm.c:343: if(frame_complete) {
	mov	a,_frame_complete
	jz	00104$
;	pwm.c:344: frame_complete = 0;
	mov	_frame_complete,#0x00
;	pwm.c:345: update();
	lcall	_update
00104$:
;	pwm.c:350: if(ch0duty != 255)
	mov	a,#0xFF
	cjne	a,_ch0duty,00136$
	sjmp	00106$
00136$:
;	pwm.c:351: ch0 = 0;
	clr	_P3_6
00106$:
;	pwm.c:353: if(ch1duty != 255)
	mov	a,#0xFF
	cjne	a,_ch1duty,00137$
	sjmp	00108$
00137$:
;	pwm.c:354: ch1 = 0;
	clr	_P3_7
00108$:
;	pwm.c:357: for(i = 255*SCALE_FACTOR; i; i--) //complete one cycle
	clr	F0
	mov	b,#0xff
	mov	a,_SCALE_FACTOR
	jnb	acc.7,00138$
	cpl	F0
	cpl	a
	inc	a
00138$:
	mul	ab
	jnb	F0,00139$
	cpl	a
	add	a,#0x01
	xch	a,b
	cpl	a
	addc	a,#0x00
	xch	a,b
00139$:
	mov	r2,a
	mov	r3,b
00115$:
	mov	a,r2
	orl	a,r3
	jz	00120$
;	pwm.c:359: if(frame_complete) break; //received an update from serial
	mov	a,_frame_complete
	jnz	00120$
;	pwm.c:361: if(ch0duty*SCALE_FACTOR == i)
	clr	F0
	mov	b,_ch0duty
	mov	a,_SCALE_FACTOR
	jnb	acc.7,00142$
	cpl	F0
	cpl	a
	inc	a
00142$:
	mul	ab
	jnb	F0,00143$
	cpl	a
	add	a,#0x01
	xch	a,b
	cpl	a
	addc	a,#0x00
	xch	a,b
00143$:
	mov	r4,a
	mov	r5,b
	cjne	a,ar2,00112$
	mov	a,r5
	cjne	a,ar3,00112$
;	pwm.c:362: ch0 = 1;
	setb	_P3_6
00112$:
;	pwm.c:364: if(ch1duty*SCALE_FACTOR == i)
	clr	F0
	mov	b,_ch1duty
	mov	a,_SCALE_FACTOR
	jnb	acc.7,00146$
	cpl	F0
	cpl	a
	inc	a
00146$:
	mul	ab
	jnb	F0,00147$
	cpl	a
	add	a,#0x01
	xch	a,b
	cpl	a
	addc	a,#0x00
	xch	a,b
00147$:
	mov	r4,a
	mov	r5,b
	cjne	a,ar2,00117$
	mov	a,r5
	cjne	a,ar3,00117$
;	pwm.c:365: ch1 = 1;
	setb	_P3_7
00117$:
;	pwm.c:357: for(i = 255*SCALE_FACTOR; i; i--) //complete one cycle
	dec	r2
	cjne	r2,#0xff,00150$
	dec	r3
00150$:
	sjmp	00115$
;------------------------------------------------------------
;Allocation info for local variables in function 'update'
;------------------------------------------------------------
;checksum                  Allocated to registers r4 
;------------------------------------------------------------
;	pwm.c:373: void update()
;	-----------------------------------------
;	 function update
;	-----------------------------------------
_update:
;	pwm.c:380: checksum = packet[1] + packet[2] + packet[3] + packet[4] + packet[5];
	mov	r2,(_packet + 0x0001)
	mov	r3,(_packet + 0x0002)
	mov	a,r3
	add	a,r2
	mov	r4,a
	mov	r5,(_packet + 0x0003)
	mov	a,r5
	add	a,r4
	mov	r4,a
	mov	r6,(_packet + 0x0004)
	mov	a,r6
	add	a,r4
	mov	r4,a
	mov	r7,(_packet + 0x0005)
	mov	a,r7
	add	a,r4
	mov	r4,a
;	pwm.c:382: if(packet[0] == 'C')
	mov	a,#0x43
	cjne	a,_packet,00102$
;	pwm.c:384: SCALE_FACTOR = packet[2];
	mov	_SCALE_FACTOR,r3
;	pwm.c:385: nOE = 1;
	setb	_P2_0
;	pwm.c:386: P2 = 0x00;
	mov	_P2,#0x00
;	pwm.c:387: P0 = 0x00;
	mov	_P0,#0x00
;	pwm.c:388: return;
	ret
00102$:
;	pwm.c:391: if(checksum != packet[6]) //checksum error
	mov	a,r4
	cjne	a,(_packet + 0x0006),00126$
	sjmp	00113$
00126$:
;	pwm.c:395: TI = 0;
	clr	_TI
;	pwm.c:396: SBUF = 0xA1;
	mov	_SBUF,#0xA1
;	pwm.c:397: while(!TI);
00103$:
;	pwm.c:399: TI = 0;
	jbc	_TI,00127$
	sjmp	00103$
00127$:
;	pwm.c:400: SBUF = checksum;
	mov	_SBUF,r4
;	pwm.c:401: while(!TI);
00106$:
	jnb	_TI,00106$
;	pwm.c:403: return;
	ret
00113$:
;	pwm.c:407: if(packet[3] == OE_ACTIVE) 
	cjne	r5,#0xAA,00110$
;	pwm.c:408: nOE = 0;// OE is a GO
	clr	_P2_0
	sjmp	00111$
00110$:
;	pwm.c:410: nOE = 1;
	setb	_P2_0
00111$:
;	pwm.c:412: ch0duty = packet[1];
	mov	_ch0duty,r2
;	pwm.c:413: ch1duty = packet[2];
	mov	_ch1duty,r3
;	pwm.c:419: P2 = packet[4];
	mov	_P2,r6
;	pwm.c:420: P0 = packet[5];
	mov	_P0,r7
	ret
;------------------------------------------------------------
;Allocation info for local variables in function 'i2c_read'
;------------------------------------------------------------
;slave_addr                Allocated to registers r2 
;byte                      Allocated to registers r2 
;------------------------------------------------------------
;	pwm.c:433: unsigned char i2c_read(unsigned char slave_addr)
;	-----------------------------------------
;	 function i2c_read
;	-----------------------------------------
_i2c_read:
	mov	r2,dpl
;	pwm.c:437: i2c_start();
	push	ar2
	lcall	_i2c_start
	pop	ar2
;	pwm.c:438: i2c_tx(slave_addr | 1); //lower bit indicates read operation
	mov	a,#0x01
	orl	a,r2
	mov	dpl,a
	lcall	_i2c_tx
;	pwm.c:440: byte = i2c_rx(1); //assert a master ack
	mov	dpl,#0x01
	lcall	_i2c_rx
	mov	r2,dpl
;	pwm.c:441: i2c_stop();
	push	ar2
	lcall	_i2c_stop
	pop	ar2
;	pwm.c:442: return byte;
	mov	dpl,r2
	ret
;------------------------------------------------------------
;Allocation info for local variables in function 'i2c_write'
;------------------------------------------------------------
;byte                      Allocated with name '_i2c_write_PARM_2'
;slave_addr                Allocated to registers r2 
;------------------------------------------------------------
;	pwm.c:446: void i2c_write(unsigned char slave_addr, unsigned char byte)
;	-----------------------------------------
;	 function i2c_write
;	-----------------------------------------
_i2c_write:
	mov	r2,dpl
;	pwm.c:450: i2c_start();
	push	ar2
	lcall	_i2c_start
	pop	ar2
;	pwm.c:452: i2c_tx(slave_addr & 0xFE); //lower bit indicates \write operation
	mov	a,#0xFE
	anl	a,r2
	mov	dpl,a
	lcall	_i2c_tx
;	pwm.c:454: i2c_tx(byte);
	mov	dpl,_i2c_write_PARM_2
	lcall	_i2c_tx
;	pwm.c:456: i2c_stop();
;	pwm.c:457: return;
	ljmp	_i2c_stop
;------------------------------------------------------------
;Allocation info for local variables in function 'i2c_start'
;------------------------------------------------------------
;------------------------------------------------------------
;	pwm.c:459: void i2c_start()
;	-----------------------------------------
;	 function i2c_start
;	-----------------------------------------
_i2c_start:
;	pwm.c:464: SDA = 1;             // i2c start bit sequence
	setb	_P1_7
;	pwm.c:465: SCL = 1;
	setb	_P1_6
;	pwm.c:466: SDA = 0;
	clr	_P1_7
;	pwm.c:467: SCL = 0;
	clr	_P1_6
	ret
;------------------------------------------------------------
;Allocation info for local variables in function 'i2c_stop'
;------------------------------------------------------------
;------------------------------------------------------------
;	pwm.c:470: void i2c_stop()
;	-----------------------------------------
;	 function i2c_stop
;	-----------------------------------------
_i2c_stop:
;	pwm.c:473: SDA = 0;  
	clr	_P1_7
;	pwm.c:474: SCL = 1; 
	setb	_P1_6
;	pwm.c:476: SDA = 1; 
	setb	_P1_7
	ret
;------------------------------------------------------------
;Allocation info for local variables in function 'i2c_tx'
;------------------------------------------------------------
;byte                      Allocated to registers r2 
;i                         Allocated to registers r3 
;------------------------------------------------------------
;	pwm.c:480: unsigned char i2c_tx(unsigned char byte) 
;	-----------------------------------------
;	 function i2c_tx
;	-----------------------------------------
_i2c_tx:
	mov	r2,dpl
;	pwm.c:485: for(i = 0x80; i; i >>= 1)
	mov	r3,#0x80
00104$:
	mov	a,r3
	jz	00107$
;	pwm.c:487: if (byte & i) 
	mov	a,r3
	anl	a,r2
	jz	00102$
;	pwm.c:488: SDA = 1;
	setb	_P1_7
	sjmp	00103$
00102$:
;	pwm.c:490: SDA = 0;
	clr	_P1_7
00103$:
;	pwm.c:492: SCL = 1;
	setb	_P1_6
;	pwm.c:493: SCL = 0; //changing of SDA only allowed when SCL = 0
	clr	_P1_6
;	pwm.c:485: for(i = 0x80; i; i >>= 1)
	mov	a,r3
	clr	c
	rrc	a
	mov	r3,a
	sjmp	00104$
00107$:
;	pwm.c:496: SDA = 1;
	setb	_P1_7
;	pwm.c:498: SCL = 1; //slave device now pulling SDA low for acknowledgement
	setb	_P1_6
;	pwm.c:500: ackbit = SDA;
	mov	c,_P1_7
	mov	_i2c_tx_ackbit_1_1,c
;	pwm.c:502: SCL = 0;
	clr	_P1_6
;	pwm.c:504: return ackbit;
	mov	c,_i2c_tx_ackbit_1_1
	clr	a
	rlc	a
	mov	dpl,a
	ret
;------------------------------------------------------------
;Allocation info for local variables in function 'i2c_rx'
;------------------------------------------------------------
;ack                       Allocated to registers r2 
;byte                      Allocated to registers r3 
;i                         Allocated to registers r4 
;------------------------------------------------------------
;	pwm.c:507: unsigned char i2c_rx(unsigned char ack)
;	-----------------------------------------
;	 function i2c_rx
;	-----------------------------------------
_i2c_rx:
	mov	r2,dpl
;	pwm.c:509: unsigned char byte = 0, i;
	mov	r3,#0x00
;	pwm.c:513: SDA = 1;
	setb	_P1_7
;	pwm.c:515: for (i = 0x80; i; i >>=1)
	mov	r4,#0x80
00109$:
	mov	a,r4
	jz	00112$
;	pwm.c:517: SCL = 1;
	setb	_P1_6
;	pwm.c:519: while(!SCL);
00101$:
	jnb	_P1_6,00101$
;	pwm.c:521: if (SDA) byte |= i; 
	jnb	_P1_7,00105$
	mov	a,r4
	orl	ar3,a
00105$:
;	pwm.c:522: SCL = 0;  
	clr	_P1_6
;	pwm.c:515: for (i = 0x80; i; i >>=1)
	mov	a,r4
	clr	c
	rrc	a
	mov	r4,a
	sjmp	00109$
00112$:
;	pwm.c:526: if(ack) SDA = 0; //assert SDA low while SCL is high?
	mov	a,r2
	jz	00107$
	clr	_P1_7
	sjmp	00108$
00107$:
;	pwm.c:527: else SDA = 1;
	setb	_P1_7
00108$:
;	pwm.c:529: SCL = 1; //clock ack bit
	setb	_P1_6
;	pwm.c:530: SCL = 0;
	clr	_P1_6
;	pwm.c:533: return byte;
	mov	dpl,r3
	ret
	.area CSEG    (CODE)
	.area CONST   (CODE)
	.area XINIT   (CODE)
	.area CABS    (ABS,CODE)
